﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Guada
{
    public partial class FrmCancelT : Plantilla
    {
        public FrmCancelT()
        {
            InitializeComponent();
        }

        private void FrmCancelT_Load(object sender, EventArgs e)
        {

        }

        private void BtnEliminar_Click(object sender, EventArgs e)
        {
            try
            {
                int aux;
                FacProFacu.Turno turno = new FacProFacu.Turno();

                for (int i = 0; i < dgTurnos.Rows.Count; i++)
                {
                    if ((bool)this.dgTurnos.Rows[i].Cells[0].Value == true)
                    {
                        aux = turno.CancelarTurno(dgTurnos.Rows[i].Cells[1].Value.ToString());
                    }
                }
                dgTurnos.Dispose();
                CargarDgTurnos(turno.GetTurnosPaciente(txtNumDoc.Text).Tables["TURNOSC"]);
            }
            catch
            {
    
            }
        }

        private void BtnCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CargarDgTurnos(DataTable Dt)
        {
            try
            {
                if (Dt.Rows.Count > 0)
                {
                    dgTurnos.DataSource = Dt;
                    DataGridViewColumn col;
                    dgTurnos.AutoGenerateColumns = false;
                    dgTurnos.Columns.Clear();

                    DataGridViewCheckBoxColumn colChk = new DataGridViewCheckBoxColumn();
                    colChk.DataPropertyName = "BOOLSINO";
                    colChk.HeaderText = "Cancelar";
                    colChk.Name = "chkSINO";
                    colChk.Width = 60; //60
                    colChk.ValueType = System.Type.GetType("System.Boolean");
                    colChk.TrueValue = true;
                    colChk.FalseValue = false;

                    colChk.ReadOnly = false;
                    dgTurnos.Columns.Add(colChk);

                    col = new DataGridViewTextBoxColumn();
                    col.DataPropertyName = "IDTURNO";
                    col.Name = "IDTURNO";
                    col.Width = 80; //50
                    col.HeaderText = "N° Turno";
                    col.ReadOnly = true;
                    dgTurnos.Columns.Add(col);

                    col = new DataGridViewTextBoxColumn();
                    col.DataPropertyName = "FECHA";
                    col.Name = "FECHA";
                    col.Width = 80;
                    col.HeaderText = "Fecha";
                    col.ReadOnly = true;
                    dgTurnos.Columns.Add(col);

                    col = new DataGridViewTextBoxColumn();
                    col.DataPropertyName = "HORA";
                    col.Name = "HORA";
                    col.Width = 60; //60
                    col.HeaderText = "Hora";
                    col.ReadOnly = true;
                    dgTurnos.Columns.Add(col);

                    col = new DataGridViewTextBoxColumn();
                    col.DataPropertyName = "PROFESIONAL";
                    col.Name = "PROFESIONAL";
                    col.Width = 150; //150
                    col.HeaderText = "Profesional";
                    col.ReadOnly = true;
                    dgTurnos.Columns.Add(col);

                    col = new DataGridViewTextBoxColumn();
                    col.DataPropertyName = "ESPECIALIDAD";
                    col.Name = "ESPECIALIDAD";
                    col.Width = 170; //150
                    col.HeaderText = "Especialidad";
                    col.ReadOnly = true;
                    dgTurnos.Columns.Add(col);

                    if (((DataTable)dgTurnos.DataSource).Rows.Count > 0)
                        dgTurnos.Rows[0].Selected = true;
                }
                else
                {
                    lblInfo.Visible = true;
                }
            }
            catch
            {

            }
        }

        private void BtnBuscar_Click(object sender, EventArgs e)
        {
            if (txtNumDoc.Text != "")
            {
                FacProFacu.Turno turno = new FacProFacu.Turno();
                CargarDgTurnos(turno.GetTurnosPaciente(txtNumDoc.Text).Tables["TURNOSC"]);
            }
        }
    }
}
